<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';//验证管理员是否登录

if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	skip('feedback_update.php','error','id参数错误！');
}

$query="select * from feedback where id={$_GET['id']}";
$result=execute($link,$query);
$data=mysqli_fetch_assoc($result);

if(!mysqli_num_rows($result)){
	skip('feedback_update.php','error','这条用户信息不存在！');
}

if(isset($_POST['submit'])){
	//转义入库
	$_POST=escape($link,$_POST);
	$query="update feedback set username='{$_POST['username']}',tel='{$_POST['tel']}',email='{$_POST['email']}',content='{$_POST['content']}',time=now() where id={$_GET['id']}";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('feedback.php','ok','恭喜你，修改成功！');
	}else{
		skip('feedback_update.php','error','对不起，修改失败，请重试！');
	}
}
$template['title']='用户留言编辑页';
$template['css']=array('style/public.css');
?>
<?php include 'inc/header.inc.php'?>
<div id="main">
	<div class="title" style="margin-bottom:20px;">编辑 - <?php echo $data['user']?> 的留言</div>
	<form method="post">
		<table class="au">
			<tr>
				<td>姓名</td>
				<td><input type="text" maxlength="200" name="username" placeholder="请输入姓名" value="<?php echo $data['username']?>" required="required" /></td>
				<td>
					姓名不得为空,请输入您的姓名
				</td>
			</tr>
			<tr>
				<td>手机号/固话</td>
				<td><input type="tel" maxlength="12" name="tel" placeholder="请输入手机号/固话" value="<?php echo $data['tel']?>" required="required" /></td>
				<td>
					手机号/固话不得为空，请输入正确的号码
				</td>
			</tr>
			<tr>
				<td>电子邮箱</td>
				<td><input type="email" name="email" placeholder="请输入电子邮箱" value="<?php echo $data['email']?>" required="required" /></td>
				<td>
					邮箱不得为空，请输入合法的电子邮件
				</td>
			</tr>
			<tr>
				<td>留言内容</td>
				<td><textarea name="content" required="required" placeholder="请输入留言内容" maxlength="200"><?php echo $data['content']?></textarea></td>
				<td>
					留言内容不得为空，不得超过200个字符
				</td>
			</tr>
		</table>
		<input style="margin-top:20px;cursor:pointer;" class="btn" type="submit" name="submit" value="提交" />
	</form>
</div>
<?php include 'inc/footer.inc.php'; close($link);?>